﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ContentManage.aspx.cs"
    Inherits="WinnerCMS.WebUI.Admin.Common.ContentManage" %>

<!doctype html>
<html>
<head runat="server">
    <title>通用管理界面</title>
    <meta charset="utf-8" />
    <meta http-equiv="Pragma" content="no-cache" />
    <%: Scripts.Render("~/Scripts/AdminBase") %>

    <%: Styles.Render("~/Content/Bootstrap/css") %>
    <style>
        .pagination {
            display: block;
        }
    </style>
    <script type="text/javascript">
        var ModelId = Request.QueryString("ModelId");
        var BaseModel = '<%= GetBaseModel %>';
        var GetContentName = '<%= GetContentName %>';
        $(function () {

            BindList();

            $("#btnDel").click(function () { OP("Del"); });
            $("#btnOntop").click(function () { OP("Ontop"); });
            $("#btnElite").click(function () { OP("Elite"); });
            $("#btnPassAll").click(function () { OP("PassAll"); });

            $("#btnAdd").click(function () { NewTabPage("添加" + GetContentName, BaseModel + "/Add.aspx?ModelId=" + ModelId + "&CategoryId=" + Request.QueryString("CategoryId")); });

            $('.icheckboxStyle').on('ifToggled', function (event) {
                //event.target.checked = !event.target.checked;
                BindList();
            });
        });
        var recordCount = 0;
        function BindList() {
            $('#t_List').datagrid({
                url: '/api/Content/List',
                queryParams: {
                    recordCount: recordCount,
                    ModelId: Request.QueryString("ModelId"),
                    FieldSort: $("#selSort").val(),
                    keyWord: $("#txtKeyWord").val(),
                    CategoryId: Request.QueryString("CategoryId") == null ? '' : Request.QueryString("CategoryId"),
                    IsEditor: $("#cbkMyWork").prop("checked"),
                    IsSpecial: $("#cbkSpecial").prop("checked"),
                    IsOnTop: $("#cbkIsOnTop").prop("checked"),
                    IsElite: $("#cbkIsElite").prop("checked"),
                    IsChecked: $("#cbkIsChecked").prop("checked"),
                    IsUnChecked: $("#cbkIsUnChecked").prop("checked"),
                    IsDraft: $("#cbkIsDraft").prop("checked"),
                    IsSlide: $("#cbkIsSlide").prop("checked")
                },
                pageSize: ConfigPageSize(),
                pageList: ConfigPageList(),
                rowStyler: function (index, row) {
                    if (row.IsChecked == 0) {
                        return 'background-color:#6293BB;color:#fff;font-weight:bold;';
                    }
                    return "";
                },
                onLoadError: function (xmlHttpRequest, textStatus, errorThrown) {
                    alert(errorThrown);
                },
                onLoadSuccess: function (data) {
                    recordCount = data.total;
                }
            });
        }
        function ContentTitleFormatter(value, rowData, rowIndex) {
            return '<a href="#" onclick="return NewTabPage(\'' + rowData.ContentTitle + '\',\'<%= GetBaseModel %>/Add.aspx?Id=' + rowData.Id + '&ModelId=' + ModelId + '\');" title="　　ＩＤ：' + rowData.Id + '&#13;&#10;　　标题：' + rowData.ContentTitle + '&#13;&#10;点 击 数：' + rowData.Hits + '">' + rowData.ContentTitle + '</a>';
        }
        function PassFormatter(value, rowData, rowIndex) {
            if (value >= 2) {
                return "<input type=\"image\" title=\"已审核\" src=\"../Images/success-true.gif\" onclick=\"OP('ContentManageManagePassOrUnPass'," + rowData.Id + ");\"> ";
            }
            else if (value <= 1) {
                return "<input type=\"image\" title=\"未审核\" src=\"../Images/failed-false.gif\" onclick=\"OP('ContentManageManagePassOrUnPass'," + rowData.Id + ");\"> ";
            }
            return "";
        }
        function ProFormatter(value, rowData, rowIndex) {
            var output = "";
            output += rowData.IsOnTop === true ? "<SPAN style=\"COLOR: blue\" title=\"固顶\">固</SPAN>" : "";
            output += rowData.IsElite === true ? "<SPAN style=\"COLOR: blue\" title=\"推荐\">荐</SPAN>" : "";
            output += rowData.IsChecked === true ? "<SPAN style=\"COLOR: blue\" title=\"已审核\">审</SPAN>" : "<del style=\"COLOR: red;\" title=\"未审核\">审</del>";
            output += rowData.IsDraft === true ? "<SPAN style=\"COLOR: red\" title=\"稿件\">稿</SPAN>" : "";
            output += rowData.IsSlide === true ? "<SPAN style=\"COLOR: blue\" title=\"幻灯片\">幻</SPAN>" : "";
            return output;
        }

        function Dateformatter(value, rowData, rowIndex) {
            return new Date(value).format("yyyy-MM-dd hh:mm:ss");
        }

        function CommentQuantityFormatter(value, rowData, rowIndex) {
            return "<a href=\"#\" onclick=\"return NewTabPage('评论管理','Common/Comment.aspx?ModelId=" + ModelId + "&ContentId=" + rowData.Id + "&Title=" + rowData.ContentTitle + "');\">" + rowData.CommentQuantity + "</a>";
        }

        function OP(action, id) {
            var ids;
            if (id != null) {
                ids = new Array(1);
                ids[0] = id;
            }
            else {
                var rows = $('#t_List').datagrid('getSelections');

                ids = new Array(rows.length);
                for (var i = 0; i < rows.length; i++) {
                    ids[i] = rows[i].Id;
                }
            }
            $.ajax({
                type: "POST",
                url: '/api/Content/' + action,
                dataType: "JSON",
                data: {
                    "IDs": ids.join(',')
                },
                success: function (info) {
                    if (info.errors.length > 0) {
                        alert(info.errors);
                    }
                    else {
                        Message("操作完成。");
                        $('#t_List').datagrid("reload");
                    }
                }
            });

        }
    </script>
</head>
<body class="easyui-layout">
    <div region="north" border="false" style="border-bottom: 1px solid #ddd; background: #fafafa; padding-left: 4px; height: 80px; overflow: hidden;">
        <div style="margin-top: 1px;clear:both;">
            <div style="float: left;">
                <input id="btnAdd" type="button" value="添加" class="btn btn-primary" />
                <select name="dore">
                    <option value="1">生成当前栏目</option>
                    <option value="2">生成首页</option>
                    <option value="3">生成父栏目</option>
                    <option value="4">生成当前栏目与父栏目</option>
                    <option value="5">生成父栏目与首页</option>
                    <option value="6">生成当前栏目、父栏目与首页</option>
                </select>
                <input type="button" value="生成" class="btn btn-default" />
            </div>
            <div style="float: right">
                <select id="selSort">
                    <option value="ContentTitle">标题</option>
                    <option value="Content">内容</option>
                    <option value="Editor">编辑</option>
                    <option value="Id">Id</option>
                </select>
                <input id="txtKeyWord" type="text">
                <button class="btn btn-default" id="btnSearch" type="button" onclick="BindList();">
                    搜索</button>
            </div>
        </div>
        <div style="margin-top: 1px;clear:both;">
        <div style="line-height: 32px; float: left; margin-top: 6px;" class="btn-group" title="编辑操作">
            <input id="btnDel" type="button" value="删除" class="btn btn-danger" />
            <input id="btnOntop" type="button" class="btn btn-default" value="置顶/消顶" />
            <input id="btnElite" class="btn btn-default" type="button" value="推荐/消荐" />
            <input id="btnPassAll" class="btn btn-default" type="button" value="审核所有" />
        </div>
        <div style="height: 30px; float: left; margin-top: 6px;margin-left:10px; padding-top: 6px;">

            <div class="icheckboxStyle">
                <input id="cbkMyWork" type="checkbox" name="cbkMyWork" />
                <label for="cbkMyWork">我的文章</label>
            </div>
            <div class="icheckboxStyle">
                <input id="cbkSpecial" type="checkbox" name="cbkSpecial" />
                <label for="cbkSpecial">专题</label>
            </div>
            <div class="icheckboxStyle">
                <input id="cbkIsOnTop" type="checkbox"
                    value="1" />
                <label for="cbkIsOnTop">置顶</label>
            </div>
            <div class="icheckboxStyle">
                <input id="cbkIsElite" type="checkbox"
                    value="1" />
                <label for="cbkIsElite">推荐</label>
            </div>
            <div class="icheckboxStyle">
                <input id="cbkIsChecked" type="checkbox"
                    value="1" checked="checked" />
                <label for="cbkIsChecked">已审核</label>
            </div>
            <div class="icheckboxStyle">
                <input id="cbkIsUnChecked" type="checkbox"
                    value="0" checked="checked" />
                <label for="cbkIsUnChecked">未审核</label>
            </div>
            <div class="icheckboxStyle">
                <input id="cbkIsDraft" type="checkbox" value="1" />
                <label for="cbkIsDraft">稿件</label>
            </div>
            <div class="icheckboxStyle">
                <input id="cbkIsSlide" type="checkbox" value="1" />
                <label for="cbkIsSlide">幻灯</label>
            </div>
        </div></div>
    </div>
    <div region="center" border="false">
        <table id="t_List" style="width: 100%; height: auto" singleselect="false" idfield="Id"
            fit="true" pagination="true" nowrap="true" striped="true" collapsible="true"
            remotesort="true" sortname="UpdateTime" sortorder="desc">
            <thead>
                <tr>
                    <th data-options="field:'',checkbox:true,width:40" align="center"></th>
                    <th field="Id" width="66" sortable="true" align="center">Id</th>
                    <th field="ContentTitle" width="320" formatter="ContentTitleFormatter" sortable="true">标题</th>
                    <th field="Editor" width="80" align="center" sortable="true">编辑</th>
                    <th field="ContentState" width="64" formatter="ProFormatter" align="center">属性</th>
                    <th field="UpdateTime" width="148" sortable="true" formatter="Dateformatter" align="center">更新日期</th>
                    <th field="CommentQuantity" width="60" sortable="true" align="right" formatter="CommentQuantityFormatter">评论数量</th>
                </tr>
            </thead>
        </table>
    </div>
</body>
</html>
